home *** CD-ROM | disk | FTP | other *** search
- { checkbit.pas -- Use custom checkmarks in menus }
-
- program CheckBit;
-
- {$R checkbit.res}
-
- uses WinTypes, WinProcs, WObjects;
-
- const
-
- id_Menu = 100; { Menu resource ID name }
- cm_Item1 = 101; { Item 1 command ID value }
- cm_Item2 = 102; { Item 2 command ID value }
- cm_Item3 = 103; { Item 3 command ID value }
- cm_Item4 = 104; { Item 4 command ID value }
- cm_Quit = 105; { Exit command ID value }
-
- Checkmark: array[0 .. 27] of Byte = (
- $ff, $ff, { 1111 1111 1111 1111 }
- $87, $c7, { 1000 0111 1100 0111 }
- $c7, $c7, { 1100 0111 1100 0111 }
- $e7, $cf, { 1110 0111 1100 1111 }
- $f3, $9f, { 1111 0011 1001 1111 }
- $f9, $3f, { 1111 1001 0011 1111 }
- $fc, $7f, { 1111 1100 0111 1111 }
- $fc, $7f, { 1111 1100 0111 1111 }
- $f9, $3f, { 1111 1001 0011 1111 }
- $f3, $9f, { 1111 0011 1001 1111 }
- $e7, $cf, { 1110 0111 1100 1111 }
- $c7, $87, { 1100 0111 1000 0111 }
- $83, $ff, { 1000 0011 1111 1111 }
- $ff, $ff { 1111 1111 1111 1111 }
- );
-
- type
-
- CheckBitApplication = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
-
- PCheckBitWindow = ^CheckBitWindow;
- CheckBitWindow = object(TWindow)
- CheckBits: HBitmap;
- constructor Init(AParent: PWindowsObject; ATitle: PChar);
- destructor Done;
- virtual;
- procedure WMCommand(var Msg: TMessage);
- virtual wm_First + wm_Command;
- end;
-
-
- {- Toggle a checkmarked menu item on or off }
- procedure ToggleCheck(Menu: HMenu; MenuItemID: Word);
- var
- MAttr, WCheck: Word;
- begin
- MAttr := GetMenuState(Menu, MenuItemID, mf_ByCommand);
- if (MAttr and mf_Checked) = mf_Checked then
- WCheck := mf_ByCommand or mf_Unchecked
- else
- WCheck := mf_ByCommand or mf_Checked;
- CheckMenuItem(Menu, MenuItemID, WCheck)
- end;
-
-
- { CheckBitApplication }
-
- {- Initialize CheckBitApplication object's window }
- procedure CheckBitApplication.InitMainWindow;
- begin
- MainWindow := New(PCheckBitWindow, Init(nil, 'CheckBit'))
- end;
-
-
- { CheckBitWindow }
-
- {- Construct CheckBitWindow object }
- constructor CheckBitWindow.Init(AParent: PWindowsObject;
- ATitle: PChar);
- var
- Mh : HMenu;
- begin
- TWindow.Init(AParent, ATitle);
- Attr.Menu := LoadMenu(HInstance, PChar(id_Menu));
- CheckBits := CreateBitmap(14, 14, 1, 1, @checkmark);
- Mh := GetSubMenu(Attr.Menu, 0);
- SetMenuItemBitmaps(Mh, cm_Item1, mf_ByCommand, 0, CheckBits);
- SetMenuItemBitmaps(Mh, cm_Item2, mf_ByCommand, 0, CheckBits);
- SetMenuItemBitmaps(Mh, cm_Item3, mf_ByCommand, 0, CheckBits);
- (* SetMenuItemBitmaps(Mh, cm_Item4, mf_ByCommand, 0, CheckBits) *)
- end;
-
- {- Destroy CheckBitWindow object and checkmark bitmap}
- destructor CheckBitWindow.Done;
- begin
- DeleteObject(CheckBits);
- TWindow.Done
- end;
-
- {- Intercept all wm_SysCommand messages }
- procedure CheckBitWindow.WMCommand(var Msg: TMessage);
- begin
- case Msg.WParam of
- cm_Item1 .. cm_Item4:
- ToggleCheck(Attr.Menu, Msg.WParam);
- cm_Quit:
- CloseWindow;
- else
- TWindow.WMCommand(Msg)
- end
- end;
-
- var
-
- CheckBitApp: CheckBitApplication;
-
- begin
- CheckBitApp.Init('CheckBitApp');
- CheckBitApp.Run;
- CheckBitApp.Done
- end.
-
-
- {--------------------------------------------------------------
- Copyright (c) 1991 by Tom Swan. All rights reserved.
- Revision 1.00 Date: 2/27/1991
- ---------------------------------------------------------------}
-